﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using ControleRepresentante.Common;
using ControleRepresentanteSync.Logic;

namespace ControleRepresentanteSync.View
{
    class ActionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SyncAction? action = value as SyncAction?;
            if (action.HasValue) return action.Value.GetDescription();

            IEnumerable<SyncAction> actions = (IEnumerable<SyncAction>) value;
            return actions.Select(x => x.GetDescription());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((string) value).ParseToEnum<SyncAction>();
        }
    }
}